package util;

import activity.discuss.DiscussActivity;
import bean.Topic;
import common.ServerConfig;
import common.UserConfig;

/**
 * Created by sshong on 15/6/9.
 */
public class LogicUtil {
    public static String getNewsUrl(String newsId, boolean wa) {
        String url = ServerConfig.SERVER_HOST + "/news/" + newsId + "?app=" + ServerConfig.API_VERSION + "&font=" + UserConfig.getFontSize();
        if (wa) {
            url += "&wa";
        }
        if (UserConfig.isNightMode()) {
            url += "&night";
        }
        if(UserConfig.isNoPic()) {
            url += "&nopic";
        }
        return url;
    }

    public static String getArticleUrl(String articleId, boolean wa) {
        String url = ServerConfig.SERVER_HOST + "/article/" + articleId + "?app=" + ServerConfig.API_VERSION + "&font=" + UserConfig.getFontSize();
        if (wa) {
            url += "&wa";
        }
        if (UserConfig.isNightMode()) {
            url += "&night";
        }
        if(UserConfig.isNoPic()) {
            url += "&nopic";
        }
        return url;
    }

    public static String getCommentsUrl(String topicId, String newsId, String articleId, String commentId) {
        String tag = null;
        String url;

        if (articleId != null && articleId.length() > 0) {
            tag = "article/" + articleId;
        } else if (newsId != null && newsId.length() > 0) {
            tag = "news/" + newsId;
        } else {
            tag = topicId;
        }

        if (null == commentId || commentId.length() == 0) {
            url = ServerConfig.SERVER_HOST + "/comments/" + tag + "?app=" + ServerConfig.API_VERSION;
        } else {
            url = ServerConfig.SERVER_HOST + "/comments/" + tag + "?app=" + ServerConfig.API_VERSION + "&id=" + commentId;
        }
        if (UserConfig.isNightMode()) {
            url += "&night";
        }
        return url;
    }

    public static String getDiscussUrl(int discussType, Topic topic) {
        switch (discussType) {
            case DiscussActivity.DISCUSS_TAB_WEIBO:
                return "http://s.weibo.com/weibo/" + topic.getDiscuss_kw();
            case DiscussActivity.DISCUSS_TAB_ZHIHU:
                return "http://www.zhihu.com/search?q=" + topic.getDiscuss_kw();
            case DiscussActivity.DISCUSS_TAB_TIANYA:
                return "http://search.tianya.cn/m/bbs.jsp?q=" + topic.getDiscuss_kw();
        }
        return "";
    }
}
